package cn.ricecode.restructure.design.observer;

import java.util.ArrayList;
import java.util.List;

public class Subject {

    private List<Observer> observerList=new ArrayList<>();

    private int state;

    public void setState(int state) {
        this.state=state;
        notifyAllObserverList();
    }

    public void addObserver(Observer observer){
        this.observerList.add(observer);
    }
    
    public void notifyAllObserverList(){
        observerList.forEach(Observer::update);
    }

}
